﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using Traceability.APP.Application.Command.Traceablitys;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Traceablitys
{
    public class GetGoodsCommandHandLer : IRequestHandler<GetGoodsCommand, APIResult<List<Goods>>>
    {

        private readonly IBaseRepostiy<Goods> _goods;

        public GetGoodsCommandHandLer(IBaseRepostiy<Goods> goods)
        {
            _goods = goods;
        }

        public async Task<APIResult<List<Goods>>> Handle(GetGoodsCommand request, CancellationToken cancellationToken)
        {
            var list = _goods.GetAll();
            return new APIResult<List<Goods>>
            {
                Code = ResultCode.Ok,
                Data = list.ToList(),
                Message = "获取成功"
            };
        }
    }
}
